<?php
/**
 * Created by PhpStorm.
 * User: 程序猴
 * QQ: 505413
 * Date: 2018/4/20
 * Time: 23:45
 */

namespace app\admin\controller;
use app\admin\controller\Base;
use payment\alipay;
use payment\wxpay;
use think\Session;
use \sms\api_demo\SmsDemo;
use think\Cache;
use think\Db;
use PHPMailer\SendEmail;

$web_url = ROOT_PATH . "extend/payment";//招商SDK目录
require_once $web_url . "/Cmblife/CmblifeUtils.php";
require_once $web_url . "/Cmblife/lib/phpseclib/Crypt/RSA.php";
require_once $web_url . "/Cmblife/lib/phpseclib/Crypt/AES.php";
require_once $web_url . "/Cmblife/lib/phpseclib/Math/BigInteger.php";
require_once $web_url . "/Cmblife/AesUtils.php";
require_once $web_url . "/Cmblife/RsaUtils.php";
require_once $web_url . "/Cmblife/URLUtils.php";
require_once $web_url . "/Cmblife/JsonUtils.php";

class Demo extends Base
{
    //企业支付宝支付表单
    public function qAlipay()
    {

        //生成订单号
        $orderNum = date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
        $this->assign('orderNum',$orderNum);
        return $this->fetch();
    }
    //企业支付宝支付
    public function qAlipayPay()
    {
        if(request()->isPost()){
            $res = Db::name('plugin')->where(array('Code'=>'qalipay'))->find();
            if($res['status'] == '1') {
                $params['subject'] = input('goods_name');//商品名字
                $params['out_trade_no'] = input('order_num');//商品订单号
                $params['total_amount'] = input('money');//付款金额
                \payment\alipay\Pagepay::pay($params);
            }else{
                $this->error('企业支付宝未开启');
            }
        }
    }
    public function ar()
    {
        //dump($_GET);exit;
        $aa = input('post.');
        $bb = input('get.');
        $this->assign('aa',$aa);
        $this->assign('bb',$bb);
    }
    //企业支付宝支付回调
    public function qAlipayNotify()
    {
        if(request()->isGet())
        {
            //支付宝返回的数据
            //dump($_GET);exit;
            $params['total_amount'] = input('total_amount');//付款金额
            $params['timestamp'] = input('timestamp');//付款时间
            $params['out_trade_no'] = input('out_trade_no');//订单编号
            $this->assign('params',$params);
            return $this->fetch();
        }
    }
    //企业微信支付
    public function qWxpay()
    {
        //生成订单号
        $orderNum = date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
        $this->assign('orderNum',$orderNum);
        return $this->fetch();
    }
    //企业微信支付
    public function qWxpayPay()
    {
        if(request()->isAjax()){
            $info = Db::name('plugin')->where(array('Code'=>'qwxpay'))->find();
            if($info['status'] == '1') {
                $params['body'] = input('body');//商品名字
                $params['out_trade_no'] = input('out_trade_no');//商品订单号
                $params['total_fee'] = input('total_fee') * 100;//付款金额
                $params['product_id'] = time();//商品id
                $info = \payment\wxpay\NativePay::getPayImage($params);
                return json(['code' => 1, 'url' => 'demo/qWxpayPay', 'info' => $info]);
            }else{
                return json(['code' => -1, 'url' => 'demo/qWxpayPay', 'msg' => '企业微信支付未开启']);
            }
        }
        return $this->fetch();
    }
    //企业微信支付回调
    public function qWxpayNotify()
    {
        //支付宝返回的数据
        if(request()->isGet()){
            dump($_GET);
        }else{
            dump($_POST);
        }

    }
    //招商信用卡支付
    public function zspay()
    {
        //生成订单号
        $orderNum = date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
        $this->assign('orderNum',$orderNum);
        return $this->fetch();
    }
    //招商支付逻辑
    public $zhaoshang_config = array();
    public function zs_pay(){
        if(request()->isAjax()){
            $paymentPlugin = Db::name('Plugin')->where("code='zspay'")->find(); // 找到支付插件的配置
            $config_value = $paymentPlugin['config_value'];
            $info = Db::name('plugin')->where(array('Code'=>'zspay'))->field('config_value')->find();
            $info = json_decode($info['config_value'],true);//反序列化
            //商户唯一ID
            $mid = $info['mid'];
            //应用唯一ID
            $aid = $info['aid'];
            //公司名字
            $merchantName = $info['merchantName'];
            //私钥
            $privateKey = $info['privateKey'];
            //公钥
            $publicKey = $info['publicKey'];
            //同步跳转地址
            $returnUrl = $info['returnUrl'];
            //异步通知地址
            $notifyUrl = $info['notifyUrl'];
            if($paymentPlugin['status'] == '1') {
                $data['order_sn'] = input('post.order_num');
                $data['user_id'] = '1';
                $data['pay_status'] = '2';
                $data['pay_code'] = 'zspay';
                $data['pay_name'] = '招商信用卡';
                $data['goods_price'] = input('post.money');
                $data['add_time'] = time();
                $data['pay_time'] = time();
                $data['discount'] = 0;
                Db::name('order')->insert($data);
                $stageNum = input('post.stageNum');
                //用于生成支付协议
                $funcName = "pay";
                $params = [
                    'mid' => $mid, //商户唯一ID，32位定长
                    'aid' => $aid, //应用唯一ID，32位定长
                    'merchantName' => $merchantName, //商户名称，App支付时必传
                    'date' => \CmblifeUtils::genDate(), //时间戳 yyyyMMddHHmmss
                    'random' => \CmblifeUtils::genRandom(), //随机字符串，保证签名不可预测，不长于32位
                    'storeNo' => '01', //门店号
                    'billNo' => input('post.order_num'), //商户订单号，同一商户需要唯一（商户自己生成）
                    'productName' => input('post.goods_name'), //订单名称（建议十个字符内）
                    'amount' => input('post.money') * 100, //订单金额（单位为分）
                    'bonus' => '0', //订单积分，无积分则传0
                    'stageNum' => input('post.stageNum'),//分期数
                    'returnUrl' => $returnUrl, //掌上生活客户端支付成功重定向页面地址，默认为掌上生活支付成功页；App支付时不需要传入
                    'notifyUrl' => $notifyUrl, //后台通知接口地址
                    'payPeriod' => '3600', //距离商户订单创建时间，剩余的可支付时间间隔（秒）
                ];
                if(empty($params['stageNum'])){
                    unset($params['stageNum']);
                }
                $prefix = $funcName;
                $cmblifeUtils = new \CmblifeUtils();
                //生成的支付协议
                $protocol = $cmblifeUtils->genProtocol($prefix, $params, $privateKey);

                //生成二维码需要的参数
                $funcName = 'releaseTagForQRPay';
                $prefix = $funcName . ".json";
                $params = [
                    'mid' => $mid, //商户唯一ID，32位定长
                    'aid' => $aid, //应用唯一ID，32位定长
                    'date' => \CmblifeUtils::genDate(), //时间戳 yyyyMMddHHmmss
                    'random' => \CmblifeUtils::genRandom(), //随机字符串，保证签名不可预测，不长于32位
                    'protocol' => $protocol,//支付协议
                ];
                $sign = $cmblifeUtils->signWithPrefixAndParams($prefix, $params, $privateKey);//通过上边的支付协议需要的参数计算出sign
                $params['sign'] = $sign;// 给到参数里

                $url = 'https://open.cmbchina.com/AccessGateway/transIn/releaseTagForQRPay.json';//二维码接口地址

                //请求方式
                $headers = [
                    'Content-Type: application/x-www-form-urlencoded',
                ];
                $data = http_build_query($params);
                //下边开始请求
                $ch = curl_init();//初始化curl
                curl_setopt($ch, CURLOPT_URL, $url);//抓取指定网页
                curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
                curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
                curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
                curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                $res = curl_exec($ch);//运行curl
                $info = curl_getinfo($ch);
                curl_close($ch);
                $checkResult = $cmblifeUtils->verifyForResponse($res, $publicKey);
                if(!$checkResult){
                    echo "响应校验失败";
                    exit(-1);
                }else{
                    $yArr = json_decode($res,true);//转成数组形式
                    $tagCode = $yArr['tagCode'];
                    if(empty($tagCode)){
                        return json(['code' => -1, 'url' => 'demo/zs_pay', 'msg' =>'二维码参数为空请重试']);
                    }else{
                        $img = "<img alt='扫码支付' src='http://qr.liantu.com/api.php?text=$tagCode'style='width:300px;height:300px;'" ;
                        return json(['code' => 1, 'url' => 'demo/zs_pay', 'data'=>$img]);
                    }

                }

            }else{
                return json(['code' => -1, 'url' => 'demo/zspay', 'msg' => '招商支付未开启']);
            }
        }
    }
    //订单退款接口
    public function zs_tui(){
        $paymentPlugin = Db::name('Plugin')->where("code='zspay'")->find(); // 找到支付插件的配置
        $config_value = $paymentPlugin['config_value'];
        $info = Db::name('plugin')->where(array('Code'=>'zspay'))->field('config_value')->find();
        $info = json_decode($info['config_value'],true);
        //商户唯一ID
        $mid = $info['mid'];
        //应用唯一ID
        $aid = $info['aid'];
        //公钥
        $publicKey = $info['publicKey'];
        $params = [
            'mid' => $mid, //商户唯一ID，32位定长
            'aid' => $aid, //应用唯一ID，32位定长
            'date' => \CmblifeUtils::genDate(), //时间戳 yyyyMMddHHmmss
            'random' => \CmblifeUtils::genRandom(), //随机字符串，保证签名不可预测，不长于32位
            'billNo' => input('order_num'),//业务订单号
            'storeNo' => '01',//门店号
            'amount' => input('money') *100,//退款金额（单位为分）
            'bonus' => '0',//退款积分
            'quantity' => '1',//订购数量
            'refundToken' => md5(time()),
        ];
        //生成二维码需要的参数
        $funcName = 'refund';
        $prefix = $funcName . ".json";
        $cmblifeUtils = new \CmblifeUtils();
        $privateKey = $info['privateKey'];
        $sign = $cmblifeUtils->signWithPrefixAndParams($prefix, $params, $privateKey);//通过上边的支付协议需要的参数计算出sign
        $params['sign'] = $sign;// 给到参数
        $data = http_build_query($params);

        $url = 'https://open.cmbchina.com/AccessGateway/transIn/refund.json';
        //请求方式
        $headers = [
            'Content-Type: application/x-www-form-urlencoded',
        ];
        //$data = http_build_query($aa);
        //下边开始请求
        $ch = curl_init();//初始化curl
        curl_setopt($ch, CURLOPT_URL, $url);//抓取指定网页
        curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);//要求结果为字符串且输出到屏幕上
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        $res = curl_exec($ch);//运行curl
        $info = curl_getinfo($ch);
        curl_close($ch);
    }
    //退款订单状态查询接口
    public function zs_tuicha()
    {
        $paymentPlugin = Db::name('Plugin')->where("code='zspay'")->find(); // 找到支付插件的配置
        $config_value = $paymentPlugin['config_value'];
        $info = Db::name('plugin')->where(array('Code'=>'zspay'))->field('config_value')->find();
        $info = json_decode($info['config_value'],true);
        $params = [
            'mid' => $info['mid'], //商户唯一ID，32位定长
            'aid' => $info['aid'], //应用唯一ID，32位定长
            'date' => \CmblifeUtils::genDate(), //时间戳 yyyyMMddHHmmss
            'random' => \CmblifeUtils::genRandom(), //随机字符串，保证签名不可预测，不长于32位
            'billNo' => input('order_num'),
            'refundToken' => md5(time()),
        ];
        //生成二维码需要的参数
        $funcName = 'getRefundOrder';
        $prefix = $funcName . ".json";
        $cmblifeUtils = new \CmblifeUtils();
        $privateKey = $info['privateKey'];
        $sign = $cmblifeUtils->signWithPrefixAndParams($prefix, $params, $privateKey);//通过上边的支付协议需要的参数计算出sign
        $params['sign'] = $sign;// 给到参数
        $data = http_build_query($params);

        $url = 'https://open.cmbchina.com/AccessGateway/transIn/getRefundOrder.json';
        //请求方式
        $headers = [
            'Content-Type: application/x-www-form-urlencoded',
        ];
        //$data = http_build_query($aa);
        //下边开始请求
        $ch = curl_init();//初始化curl
        curl_setopt($ch, CURLOPT_URL, $url);//抓取指定网页
        curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);//要求结果为字符串且输出到屏幕上
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        //dump($arr);exit;
        $res = curl_exec($ch);//运行curl
        $info = curl_getinfo($ch);
        curl_close($ch);
    }
    /************************************第三方登录******************************************/
    //微博登录
    public function weibo()
    {
        $res = Db::name('plugin')->where(array('Code'=>'wb_login'))->find();
        $info = Db::name('plugin')->where(array('Code'=>'wb_login'))->field('config_value')->find();
        $info = json_decode($info['config_value'],true);
        $appKey = $info['appid'];//key
        $this->assign('appKey',$appKey);
        $this->assign('res',$res);
        return $this->fetch();
    }
    //微博登录回调
    public function weiboNotify()
    {
        header("Content-Type:text/html;charset=utf-8");
        $info = Db::name('plugin')->where(array('Code'=>'wb_login'))->field('config_value')->find();
        $info = json_decode($info['config_value'],true);//反序列化

        if(request()->isGet()){
            $client_id = $info['appid'];//appid
            $client_secret = $info['secret'];//secret
            $redirect_uri = $info['huidiao'];//回调地址
            $code = input('get.code');//调用接口接收过来的code
            $url = "https://api.weibo.com/oauth2/access_token?client_id=". $client_id ."&client_secret=".$client_secret ."&grant_type=authorization_code&redirect_uri=" . $redirect_uri . "&code=" . $code;
            //跨域请求
            $curl = curl_init();
            curl_setopt($curl, CURLOPT_URL, $url);
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl, CURLOPT_POST, TRUE);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
            $data = curl_exec($curl);//获取到的数据
            curl_close($curl);
            $result = json_decode($data, true);//转成数组

            $access_token = $result['access_token'];//token
            $uid = $result['uid'];

            $user = "https://api.weibo.com/2/users/show.json?access_token=". $access_token ."&uid=" . $uid;//获取到用户信息
            //dump($user);
            $data =  file_get_contents($user);//获取到详细用户信息
            $data = json_decode($data, true);
            if(empty($data)){
                $this->error('系统升级中，请稍后重试');
            }else{
                if(false === $data){
                    $this->error('登录失败，请重试');
                }else{
                    $name = $data['name'];
                    $location = $data['location'];
                    $profile_image_url = $data['profile_image_url'];
                    $followers_count = $data['followers_count'];
                    //登录成功之后通过get方式把要获取的信息给到weiboIndex方法   这里thinkphp 必须用普通模式  'url_common_param'       => true,改成true
                    $this->success('登录成功',url("demo/weiboIndex",array('name'=>$name,'location'=>$location,'profile_image_url'=>$profile_image_url,'followers_count'=>$followers_count)));
                }
            }
        }
    }
    //微博信息展示
    public function weiboIndex(){
        if(request()->isGet()){
            $data['name'] = input('name');
            $data['location'] = input('location');
            $data['profile_image_url'] = input('profile_image_url');
            $data['followers_count'] = input('followers_count');
            $this->assign('data',$data);
        }
        return $this->fetch();
    }
    //QQ登录
    public function qq()
    {
        $res = Db::name('plugin')->where(array('Code'=>'qq_login'))->find();
        $info = Db::name('plugin')->where(array('Code'=>'qq_login'))->field('config_value')->find();
        $info = json_decode($info['config_value'],true);

        $appid = $info['appid'];//appid
        $notify =  $info['huidiao'];//回调地址
        $this->assign('appid',$appid);
        $this->assign('notify',$notify);
        $this->assign('res',$res);
        return $this->fetch();
    }
    //QQ登录回调
    public function qqNotify()
    {
        header("Content-Type:text/html;charset=utf-8");
        $info = Db::name('plugin')->where(array('Code'=>'qq_login'))->field('config_value')->find();
        $info = json_decode($info['config_value'],true);
        if(request()->isGet()) {
            $client_id = $info['appid'];//appid
            $client_secret = $info['secret'];//secret
            $redirect_uri = $info['huidiao'];//回调地址
            $code = input('get.code');//调用接口接收过来的code
            $token_url = "https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id=" . $client_id . "&client_secret=" . $client_secret . "&code=".$code."&state=test&redirect_uri=" . $redirect_uri;
            $response = file_get_contents($token_url);
            //dump($response);
            //获取用户OpenID
            $params = array();
            parse_str($response, $params);//把传回来的数据参数变量化
            $graph_url = "https://graph.qq.com/oauth2.0/me?access_token=".$params['access_token'];
            $str = file_get_contents($graph_url);
            if (strpos($str, "callback") !== false)
            {
                $lpos = strpos($str, "(");
                $rpos = strrpos($str, ")");
                $str = substr($str, $lpos + 1, $rpos - $lpos -1);
            }
            $user = json_decode($str);//存放返回的数据 client_id ，openid
            $user_data_url = "https://graph.qq.com/user/get_user_info?access_token={$params['access_token']}&oauth_consumer_key={$client_id}&openid={$user->openid}&format=json";

            $user_data = file_get_contents($user_data_url);//此为获取到的user信息
            $data = json_decode($user_data, true);
            if(empty($data)){
                $this->error('系统升级中，请稍后重试');
            }else{
                if(false === $data){
                    $this->error('登录失败，请重试');
                }else{
                    $nickname = $data['nickname'];
                    $province = $data['province'];
                    $city = $data['city'];
                    $year = $data['year'];
                    $figureurl_1 = $data['figureurl_1'];
                    //登录成功之后通过get方式把要获取的信息给到weiboIndex方法   这里thinkphp 必须用普通模式  'url_common_param'       => true,改成true
                    $this->success('登录成功',url("demo/qqIndex",array('nickname'=>$nickname,'province'=>$province,'city'=>$city,'year'=>$year,'figureurl_1'=>$figureurl_1)));
                }
            }
        }
    }
    //qq登录信息展示
    public function qqIndex()
    {
        if(request()->isGet()){
            $data['nickname'] = input('nickname');
            $data['province'] = input('province');
            $data['city'] = input('city');
            $data['year'] = input('year');
            $data['figureurl_1'] = input('figureurl_1');
            $this->assign('data',$data);
        }
        return $this->fetch();
    }
    /************************************阿里短信******************************************/
    //发送短信
    public function aliSms()
    {
        if(request()->isAjax()){
            $res = Db::name('plugin')->where(array('Code'=>'aliSms'))->find();
            if($res['status'] == '1') {
                $tel = input('get.tel');
                if (!empty($tel)) {
                    if (!preg_match("/1[3578]{1}\d{9}$/", $tel)) {
                        return json(['code' => -2, 'url' => 'demo/aliSms', 'msg' => '手机号格式不正确']);
                    }
                    if (Cache::get(('sms_' . $tel . '_status'))) {
                        return json(['code' => -3, 'url' => 'demo/aliSms', 'msg' => '请60秒后再次发送短信']);
                    }
                    $code = mt_rand(1000, 9999);
                    set_time_limit(0);
                    $result = SmsDemo::sendSms($tel, $code);
                    $result = get_object_vars($result);
                    if ($result['Code'] === 'OK') {                      //对象转数组
                        Cache::set('sms_' . $tel . '_code', $code, 3600 * 5); //短信有效期为 5 分钟
                        Cache::set('sms_' . $tel . '_status', 1, 60);        //60秒内禁止再次发送
                        //dump( Cache::get('sms_'.$tel.'_code'));dump(Cache::get('sms_'.$tel.'_status'));
                        header('Content-Type: text/plain; charset=utf-8');
                        return json(['code' => 1, 'url' => 'demo/aliSms', 'msg' => '短信发送成功']);
                    } else {
                        return json(['code' => -4, 'url' => 'demo/aliSms', 'msg' => '短信发送失败']);
                    }
                } else {
                    return json(['code' => -1, 'url' => 'demo/aliSms', 'msg' => '手机号不能为空']);
                }
            }else{
                return json(['code' => -5, 'url' => 'demo/aliSms', 'msg' => '阿里短信未开启']);
            }
        }
        return $this->fetch();
    }
    //验证短信
    public function vCode(){
        if(request()->isAjax()){

            $tel    =   input('post.tel');
            $code   =   input('post.vcode');
            if(empty($tel)){
                return json(['code' => -1, 'url' => 'demo/aliSms', 'msg' => '手机号码不能为空']);
            }else {
                $verCode = Cache::get('sms_'.$tel.'_code');
                if(empty($code)){
                    return json(['code' => -3, 'url' => 'demo/aliSms', 'msg' => '请填写验证码']);
                } else {
                    if($code != $verCode){
                        return json(['code' => -4, 'url' => 'demo/aliSms', 'msg' => '验证码不正确']);
                    } else {
                        return json(['code' => 1, 'url' => 'demo/aliSms', 'msg' => '登录成功']);
                    }
                }
            }
        }
    }
    /************************************邮件功能******************************************/
    //邮件页面
    public function Email()
    {
        if(request()->isAjax()){
            $res = Db::name('plugin')->where(array('Code'=>'mail'))->find();
            if($res['status'] == '1') {
                $mail = input('get.mail');
                if (!empty($mail)) {
                    $code = mt_rand(1000, 9999);
                    set_time_limit(0);
                    $title = '程序猴验证码';//邮件标题
                    $message = '您的验证码是' . $code;//邮件内容
                    $emailAddress = $mail;//收件人地址
                    $result = SendEmail::SendEmail($title, $message, $emailAddress);
                    //dump($result);exit;
                    if (false === $result) {
                        return json(['code' => -2, 'url' => 'demo/Email', 'msg' => '发送失败']);
                    } else {
                        Cache::set('sms_' . $mail . '_code', $code, 3600 * 5); //邮件有效期为 5 分钟
                        Cache::set('sms_' . $mail . '_status', 1, 60);        //60秒内禁止再次发送
                        //dump( Cache::get('sms_'.$tel.'_code'));dump(Cache::get('sms_'.$tel.'_status'));
                        header('Content-Type: text/plain; charset=utf-8');
                        return json(['code' => 1, 'url' => 'demo/Email', 'msg' => '发送成功']);
                    }
                } else {
                    return json(['code' => -1, 'url' => 'demo/Email', 'msg' => '邮箱地址不能为空']);
                }
            }else{
                return json(['code' => -3, 'url' => 'demo/qWxpayPay', 'msg' => '邮件功能未开启']);
            }
        }
        return $this->fetch();
    }
    //验证邮箱
    public function vCodeMail(){
        if(request()->isAjax()){
            $mail    =   input('post.mail');
            $code   =   input('post.vcode');
            if(empty($mail)){
                return json(['code' => -1, 'url' => 'demo/Email', 'msg' => '邮箱地址不能为空']);
            }else {
                $verCode = Cache::get('sms_'.$mail.'_code');
                if(empty($code)){
                    return json(['code' => -3, 'url' => 'demo/Email', 'msg' => '请填写验证码']);
                } else {
                    if($code != $verCode){
                        return json(['code' => -4, 'url' => 'demo/Email', 'msg' => '验证码不正确']);
                    } else {
                        return json(['code' => 1, 'url' => 'demo/Email', 'msg' => '登录成功']);
                    }
                }
            }
        }
    }
}